package com.leyou.trade.service.impl;

import com.leyou.trade.constants.PayConstants;
import com.leyou.trade.entity.Order;
import com.leyou.trade.enums.OrderStatus;
import com.leyou.trade.service.OrderService;
import com.leyou.trade.service.PayService;
import com.leyou.trade.utils.PayHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class PayServiceImpl implements PayService {
    @Autowired
    private PayHelper payHelper;

    @Autowired
    private OrderService orderService;
    @Override
    public String getPayUrl(Long orderId) {

        Order order = this.orderService.getById(orderId);
        String payUrl=payHelper.getPayUrl(orderId,1L/*order.getActualFee*/, PayConstants.ORDER_DESC);
        return payUrl;
    }
//
//    @Override
//    public Integer getOrderStatus(Long orderId) throws Exception{
//        //查询微信支付的响应结果
//        Map<String, String> resp = payHelper.queryOrderStatus(orderId);
//
//        for (Map.Entry<String, String> stringStringEntry : resp.entrySet()) {
//            System.out.println(stringStringEntry);
//        }
//
//        //获取状态值
//        String trade_state = resp.get("trade_state");
//        //判断状态值并返回响应结果给到前端
//        if (trade_state.equals("SUCCESS")){
//            return OrderStatus.PAY_UP.getValue();//支付成功
//        }else if (trade_state.equals("NOTPAY")){
//            return OrderStatus.INIT.getValue();//未支付
//        }
//        return null;
//    }
}
